package Text32;
import java.util.*;
public class Main {
    static int N = 10010;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        PriorityQueue<Integer> p = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            int a=scanner.nextInt();
            p.offer(a);
        }
        while(p.size()>1){
            int x=p.poll();
            int y=p.poll();
            p.offer(x+y);
        }
        System.out.println(p.poll());
    }
}
